package com.qcu.service.impl;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qcu.dto.chart.HotProduct;
import com.qcu.entity.ExaminationInfo;
import com.qcu.entity.OrderInfo;
import com.qcu.service.ExaminationInfoService;
import com.qcu.service.OrderInfoService;
import com.qcu.mapper.OrderInfoMapper;
import com.qcu.util.Response;
import com.qcu.util.ResponseCode;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
* @author MyComputer
* @description 针对表【order_info】的数据库操作Service实现
* @createDate 2025-04-09 09:41:25
*/
@Service
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo>
    implements OrderInfoService{

    @Resource
    private OrderInfoMapper orderInfoMapper;

    @Resource
    private ExaminationInfoService examinationInfoService;

    @Override
    public Response getExamInfo(String inhabitantId) {
        List<String> examInfo = orderInfoMapper.getExamInfo(inhabitantId);
        if (examInfo.isEmpty()){
            return Response.failure(ResponseCode.FAILURE);
        }
        HashMap<String, String> map = new HashMap<>();
        for (String s : examInfo) {
            HashMap<String,String> parse = (HashMap<String, String>) JSON.parse(s);
            map.putAll(parse);
        }
        // 将集合转换为list
//        List<String> list = new ArrayList<>(item);
        ExaminationInfo examinationInfo = new ExaminationInfo();
        examinationInfo.setId(inhabitantId);
        examinationInfo.setContent(JSON.toJSONString(map));
        examinationInfo.setState(0);

        examinationInfoService.save(examinationInfo);


        return Response.success(map);
    }

    @Override
    public List<HotProduct> getHotProduct() {
        return orderInfoMapper.getHotProduct();
    }
}




